﻿// java script chart v1.0.0, saturday Aug 09 17:00:00 CET 2008

// Copyright (c) 2008 
// Author: Xu ChangGong MSN:xuchanggong@hotmail.com GMail:xuchanggong@gmail.com
// 
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
// 
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
JSCHART_RIGHT = 0;
JSCHART_LEFT = 1;
JSCHART_TOP = 2;
JSCHART_BOTTOM = 3;
TICKS_NONE = 0;
TICKS_ALL = 1;
GRID_LINES_NONE = 0;
GRID_LINES_ALL = 1;
function LegendProperties(placement, columnsNum, lwidth, lheight) {
	this.placement = placement;
	this.columnsNum = columnsNum;
	this.itemWidth = lwidth;
	this.itemHeight = lheight;
};

function jsChart() {
	this.boder={};
	this.legendLabels = new Array();
	this.datas = new Array();
	this.paints = new Array();
	this.chartTitle = '';
	this.canvasID = '';
	this.canvasWidth = 500;
	this.canvasHeight = 500;
	this.jsc_ua = navigator.userAgent.toLowerCase();
	this.jsc_ie = !!(!window.opera && document.all && (document.documentElement || document.body));
	this.jsc_iemac = !!(this.jsc_ie && this.jsc_ua.indexOf('mac') >= 0);
	this.jsc_kq = !!(this.jsc_ua.indexOf('konqu') >= 0);
	this.jsc_db = document.documentElement || document.body || null;
	this.jsc_adhtm = undefined; 
	this.jsc_dom = undefined;
	this.jsc_moz = document.body && typeof document.body.style.MozOpacity != "undefined";
	this.legend = undefined;
};

jsChart.prototype.getCnvPos = function(canvas) {
	this.jsc_pageX = this.canvasLeft+1;
	this.jsc_pageY = this.canvasTop;
	o = canvas;
	while (o.offsetParent)
	{
		this.jsc_pageX += o.offsetLeft;
		this.jsc_pageY += o.offsetTop;
		o = o.offsetParent;
	}
};

jsChart.prototype.getDiv = function(x) {
	x = !!document.all? document.all[x] : !!document.getElementById? document.getElementById(x) : null;
	return (x && typeof x.style != 'undefined' && typeof x.innerHTML != 'undefined')? x : null;
};

jsChart.prototype.isNum = function(x) {
	return (!isNaN(x) && typeof x == 'number');
};

jsChart.prototype.gReplace = function(x) {
	return x.replace(/%%([^;]+);([^;]+);([^;]+);([^;]+);([^;]+);([^;]*);([^;]+);([^%%]*)/g,
		'<div style="position:absolute;left:$1px;top:$2px;width:$3px;height:$4px;text-align:$5t;'+
		'background:$6;overflow:$7;"$8<\/div>');
};

jsChart.prototype.paint = function(cnv, htm, add) {
	if (cnv)
	{
		if (!this.jsc_adhtm) {
			this.jsc_adhtm = (typeof cnv.insertAdjacentHTML != "undefined");
		}
		if (!this.jsc_dom) {
			this.jsc_dom = (!this.jsc_adhtm &&
			typeof cnv.appendChild != "undefined" &&
			typeof document.createRange != "undefined" &&
			typeof (o = document.createRange()).setStartBefore != "undefined" &&
			typeof o.createContextualFragment != "undefined");
		}
		if (add)
		{
			var o;
			if (this.jsc_adhtm) cnv.insertAdjacentHTML("BeforeEnd", this.gReplace(htm));
			else if (this.jsc_dom)
			{
				o = document.createRange();
				o.setStartBefore(cnv);
				o = o.createContextualFragment(htm);
				cnv.appendChild(o);
			}
			else cnv.innerHTML += htm;
		}
		else cnv.innerHTML = this.jsc_ie? this.gReplace(htm) : htm;
	}
};

jsChart.prototype.mkDiv = function(txt, align, x, y, w, h, c, id, over, cut,pos,titleText,addStyle)
{
	if (cut)
	{
		if (x-this.canvasWidth > 0 || x+w < 0 || y-this.canvasHeight > 0 || y+h < 0) return '';
		if (y < 0)
		{
			h += y;
			y = 0;
		}
		if (y+h-this.canvasHeight-1 > 0) h = this.canvasHeight+1-y;
		if (x < 0)
		{
			w += x;
			x = 0;
		}
		if (x+w-this.canvasWidth-1 > 0) w = this.canvasWidth+1+x;
	}
	return ('<div'+
		(id? ' id="'+id+'"' : '')+
		(titleText? ' title="'+titleText.JSCEncode('')+'"' : '')+
		' style="'+(pos? '' : 'position:absolute;left:' + x + 'px;top:' + y + 'px;width:' + w + 'px;height:' + h + 'px;')+
		(over? '' : ('clip:rect(0,' + w + 'px,' + h + 'px,0);' + (this.jsc_moz? '' : 'overflow:hidden;')))+
		(c? 'background-color:' + c + ';' : '')+(addStyle ? addStyle : '')+
		'text-align:' + (align || 'left') + ';">' + txt + '<\/div>'
	);
};
String.prototype.JSCEncode = function(rr)
{ if (this==null) return(rr);
	vv = this;
  var ss=String(vv);
  while (ss.search("'")>=0) ss=ss.replace("'","&#39;");
  return(ss);
}
jsChart.prototype.adjustCanvas = function()
{
	this.Canvas.style.width = this.canvasWidth+'px';
	this.Canvas.style.height = this.canvasHeight+'px';
};
document.write('<div id="hinttip" style="position:absolute; border:1px #000000 solid; visibility:hidden;"> </div>');
